﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectCommonLibs.utils
{
    public class MathUtils
    {
        public static int getSignedInt(byte[] data, int startIndex)
        {
            byte[] temp = { data[startIndex + 3], data[startIndex + 2], data[startIndex + 1], data[startIndex] };
            return BitConverter.ToInt32(temp, 0);
        }
        public static uint getInt(byte[] data, int startIndex)
        {
            byte[] temp = { data[startIndex + 3], data[startIndex + 2], data[startIndex + 1], data[startIndex] };
            return BitConverter.ToUInt32(temp, 0);
        }
        public static short getSignedShort(byte[] data,int startIndex)
        {
            byte[] temp = { data[startIndex + 1], data[startIndex] };
            return BitConverter.ToInt16(temp, 0);
        }
        public static ushort getShort(byte[] data,int startIndex)
        {
            byte[] temp = { data[startIndex + 1], data[startIndex] };
            return BitConverter.ToUInt16(temp, 0);
        }
        public static int returnDataLength(byte[] command)
        {
            var start = getShort(command, 4);
            var end = getShort(command, 2);
            return (start - end) * 2 + 5;
        }
    }
}
